# -*- coding: utf-8 -*-
# @Time    : 2023/12/25 16:11
# @Author  : kl
# @File    : testaddProject.py

from pages.add_project_page import AddProjectPage
from playwright.sync_api import expect
import pytest
import allure

class TestAddProject:
    """添加项目"""
    @pytest.fixture(autouse=True)
    def start_for_each(self, page):
        print("for each--start: 打开添加项目页")
        self.add_project = AddProjectPage(page)
        self.add_project.navigate()
        yield
        print("for each--end: 后置操作")

    @pytest.mark.parametrize("name, app, desc", [
    ["abc!@", "", ""],
    ["aaaaabbbbbcccccdddddeeeeefffff1", "", ""],
    ["abc", "aa!@", ""]
    ])
    def test_add_project_disabled(self, name, app, desc):
        """异常场景-项目名称，无效等价：特殊字符/大于30个字符"""
        self.add_project.fill_project_name(name)
        self.add_project.fill_publish_app(app)
        self.add_project.fill_project_desc(desc)
        # 断言提交按钮状态 不可点击
        expect(self.add_project.locator_save_button).to_be_disabled()

    def test_add_project_null(self):
        """异常场景-项目名称不能为空"""
        self.add_project.fill_project_name("")
        self.add_project.fill_publish_app("")
        self.add_project.fill_project_desc("")
        self.add_project.click_save_button()
        # 断言提交按钮状态 不可点击
        expect(self.add_project.locator_save_button).to_be_disabled()

    def test_add_project_success(self, page):
        """提交成功，跳转到项目列表"""
        import uuid
        # 生成随机账号
        self.add_project.fill_project_name(str(uuid.uuid4()).replace('-', '')[:25])
        self.add_project.fill_publish_app("xx")
        self.add_project.fill_project_desc("xxx")
        # 断言跳转到项目列表页
        with page.expect_navigation(url="**/list_project.html"):
            # 保存成功后，重定向到列表页
            self.add_project.click_save_button()